<?php
echo '<link rel="stylesheet" type="text/css" href="' . base_url() . 'css/style_master.css" media="print" />';
echo '<link rel="stylesheet" type="text/css" href="' . base_url() . 'css/jdate_picker/jquery.ui.all.css" media="print" />';
echo '<link rel="stylesheet" type="text/css" href="' . base_url() . 'css/demo_table.css" media="print" />';
?>

<style type="text/css">
    p a{
        color:#4F815C;
        text-decoration: none

    }
    input[class="my_search"][type="submit"] {
        background-image: url("../images/image_search/icon-22-search.png") !important;
        border: medium none;
        cursor: pointer;
        height: 23px !important;
        width: 23px !important;
    }
    #color{color:red;font-weight: bold;}

</style>
<script type="text/javascript">
    function printPage()
    {
            
        var html="<html>";
        html+= document.getElementById('day').innerHTML;
        html+="</html>";

        // var printWin = window.open('','','left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status  =0');
        var printWin= window.open('','','left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status  =0');
        printWin.document.write(html);
        printWin.document.close();
        printWin.focus();
        printWin.print();
        printWin.close();
        
        var html="<html>";
        html+="<head>";
        html+="<style type='text/css'>table #mytable tr {border:1px #ccc solid;}#mytable tr td{border:1px solid #ccc;}a img #image{display:none;}</style>";
        html+="<link rel='Stylesheet' type='text/css' href='<?php echo base_url(); ?>css/report.css' media='print' />";
        html+="</head>";
        html+= document.getElementById('day').innerHTML;
        html+="</html>";
    }
</script>
<br/><br/>
<div class="task1" id="day">
    <?php
    echo '<div>';   
    echo '<fieldset   bgcolor="blue" style="margin: 0 auto; width:91.5%;height: auto;border: 1px #ccc solid; padding:20px 4px 20px 4px;-moz-border-radius:10px;">';
    echo '<div style="float: right; border: 0px #ccc solid; margin-right: 15px;">';
    echo anchor('report/manager', img('images/user_images/cancel.png'));
    echo '</div>';
    echo '<div id="subheader">';
    echo img(array('src' => 'images/NRY001_Logo-FINAL-master_01-horiz.jpg', 'alt' => 'logo', 'align' => 'left', 'width' => '150'));
    echo'</div>';
    echo '<h2 style="text-align:center;color:#008000;">Today Report</h2>';
    echo '<br/><div style="float:right;color:#008000;width:28%; text-align:center;">View Daily Report For Day:' . '<b style="color:red;">  &nbsp;' . date("F/d/Y") . '</b><br/>';
    ?>
    To print this report, Click here <a href="#"><img src="<?php echo base_url(); ?>/images/user_images/print.png" align="center" onclick="printPage('day')" id="image"  alt="Print daily report" title="Print daily report"/></a>
</div> 
<?php
//=================query for select data for card public that has sold===============
$dailyselect = $this->db->query('SELECT *
        FROM tbl_sale
        INNER JOIN tbl_card ON tbl_card.car_id = tbl_sale.car_id
        JOIN tbl_car_type ON tbl_car_type.car_type_id = tbl_card.car_type_id
        WHERE sal_date = curdate( ) and car_type_name="public" ');
$this->db->where('sal_date=curdate()');
$datall = $this->db->get('tbl_sale');
if ($datall->num_rows() > 0) {
    if ($dailyselect->num_rows() > 0) {
        echo ' <div style="border:0px solid #ccc;font-size:20px;width:30%;margin:auto;text-align:center;padding:10px 0px 10px 0px;color:#5A8F15;">Public Class</div>';
        echo '<br/>';
        echo '<table id="mytable" width="100%" cellspacing="0" cellpadding="0"><tr>
              <tr style="height:28px;color:#FFF;text-align:center;">
                <th style="border:1px solid #ccc;">N&ordm</th>
                <th  style="border:1px solid #ccc;">Date</th>
                <th  style="border:1px solid #ccc;">Seller</th>
                <th  style="border:1px solid #ccc;">Items</th>
                <th  style="border:1px solid #ccc;">Quantity</th>
                <th  style="border:1px solid #ccc;">Unit Price</th>
                <th  style="border:1px solid #ccc;">Payment</th>
                <th  style="border:1px solid #ccc;">Credit</th>
              </tr>';
        $i = 1;
        $j = 0;
        foreach ($dailyselect->result() as $value) {
            $j++;
            echo '<tr style="text-align:center;font-weight: lighter;" class="row';
            echo $j % 2;
            echo '">';
            echo '<td style="text-align:center; border:1px solid #ccc;">' . $j . '</td>
                  <td style="text-align:center; border:1px solid #ccc;">' . $value->sal_date . '</td>
                  <td style="text-align:center; border:1px solid #ccc;">' . $this->session->userdata('use_username') . '</td>
                  <td style="text-align:center; border:1px solid #ccc;">' . $value->car_name . '</td>
                  <td style="text-align:center; border:1px solid #ccc;">' . $value->sal_quantity . '</td>
                  <td style="text-align:center; border:1px solid #ccc;">$' . $value->sal_price . '</td>
                  <td style="text-align:center; border:1px solid #ccc;">$' . $value->sal_payment . '</td>
                  <td style="text-align:center; border:1px solid #ccc;" >$' . ($value->sal_quantity * $value->sal_price - $value->sal_payment) . '</td>
                  </tr>';
            $i++;
        }

        //===================query in order to select data for total and Credit card public ======================

        $datas = $this->db->query('SELECT SUM(sal_quantity*sal_price)AS total, SUM(sal_quantity * sal_price - sal_payment) AS credit FROM tbl_sale
INNER JOIN tbl_card ON tbl_card.car_id = tbl_sale.car_id join tbl_car_type on tbl_car_type.car_type_id=tbl_card.car_type_id 
WHERE sal_date = curdate( ) and car_type_name="public"');

        echo '<tr style="background-color:#E8F6FE;">';
        echo ' <td colspan="6" style="text-align:right;font-size:18px;color:red;font-weight:Bold; border:1px solid #ccc;">Total:</td>';
        foreach ($datas->result() as $value) {
            echo '<td style="color:red;text-align:center;font-weight:Bold;border:1px solid #ccc;" >$' . $value->total . '</td>';
            echo '<td style="color:red;font-weight:Bold;text-align:center;border:1px solid #ccc;">$' . $value->credit . '</td>';
        }
        echo ' </tr>';
        echo '</table>';
    }
    echo '<br/>';

    //==========================View of Private card that sold============================
    //================query select data for card private=============
    $dataprivate = $this->db->query('SELECT *FROM tbl_sale
        INNER JOIN tbl_card ON tbl_card.car_id = tbl_sale.car_id join tbl_car_type on tbl_car_type.car_type_id=tbl_card.car_type_id
          WHERE sal_date = curdate( ) and car_type_name="private" ');

    if ($dataprivate->num_rows() > 0) {
        echo '<div style="font-size:20px;width:50%;margin:auto;text-align:center;padding:10px 0px 10px 0px;color:#5A8F15;">Private Class and WorkShop/Retreat</div>';
        echo '<table id="mytable" width="100%" cellspacing="0" cellpadding="0" > 
              <tr style="height:28px;color:#FFF;text-align:center;">
                <th style="border:1px solid #ccc;">N&ordm</th>
                <th style="border:1px solid #ccc;">Sele Date</th>
                 <th style="border:1px solid #ccc;">Seller</th>
                <th style="border:1px solid #ccc;">Items</th>
                <th style="border:1px solid #ccc;">Quantity</th>
                <th style="border:1px solid #ccc;">Unit Price</th>
                <th style="border:1px solid #ccc;">Payment</th>
                <th style="border:1px solid #ccc;">Credit</th>
              </tr>';
        $j = 0;
        $i = 1;
        foreach ($dataprivate->result() as $value) { //======================loop data from database as a row ================
            $j++;
            echo '<tr style="color:red;text-alig:center;color:black;font-weight:Bold;border:1px solid #ccc; font-weight:lighter;" class="row';
            echo $j % 2;
            echo '">';
            echo '<td style="text-align:center; border:1px solid #ccc;" >' . $j . '</td>
                  <td style="text-align:center; border:1px solid #ccc;" >' . $value->sal_date . '</td>
                  <td style="text-align:center; border:1px solid #ccc;" >' . $this->session->userdata('use_username') . '</td>
                  <td style="text-align:center; border:1px solid #ccc;" >' . $value->car_name . '</td>
                  <td style="text-align:center; border:1px solid #ccc;" >' . $value->sal_quantity . '</td>
                  <td style="text-align:center; border:1px solid #ccc;" >$' . $value->sal_price . '</td>
                  <td style="text-align:center; border:1px solid #ccc;" >$' . $value->sal_payment . '</td>
                  <td style="text-align:center; border:1px solid #ccc;" >$' . ($value->sal_quantity * $value->sal_price - $value->sal_payment) . '</td>
                  </tr>';
            $j++;
        }

        //=================query select data for total private card and total credit private card=================

        $datapr = $this->db->query('SELECT SUM(sal_quantity*sal_price)AS totals, SUM(sal_quantity * sal_price - sal_payment) AS creditp FROM tbl_sale
INNER JOIN tbl_card ON tbl_card.car_id = tbl_sale.car_id join tbl_car_type on tbl_car_type.car_type_id=tbl_card.car_type_id 
WHERE sal_date = curdate( ) and car_type_name="private"');
        echo '<tr style="background-color:#E8F6FE;">';
        echo ' <td colspan="6" style="text-align:right;font-size:16px;color:red;font-weight:Bold;">Total:</td>';
        foreach ($datapr->result() as $value) {
            echo '<td style="color:red;text-align:center;border:1px solid #ccc;font-weight:Bold;">$' . $value->totals . '</td>';
            echo '<td style="color:red;font-weight:Bold;text-align:center;border:1px solid #ccc;">$' . $value->creditp . '</td>';
        }
        echo ' </tr>';
    }
    echo '</table>';
    echo '<br/>';

    //===================Query to get data form database to display tatal amount, credit amount===============
    $data_total_amount = $this->db->query('SELECT  sum(sal_quantity * sal_price ) as total_amount , sum(sal_quantity * sal_price - sal_payment) AS credit_amount
FROM tbl_sale
INNER JOIN tbl_card ON tbl_card.car_id = tbl_sale.car_id
JOIN tbl_car_type ON tbl_car_type.car_type_id = tbl_card.car_type_id
WHERE sal_date = curdate( )  ');

    //============query select data for total product and total credit product====================
    $data_product_amount = $this->db->query('SELECT  sum(sal_quantity * sal_price ) AS total_pro,sum(sal_quantity * sal_price - sal_payment) AS credit
FROM tbl_sale
INNER JOIN tbl_product ON tbl_product.pro_id = tbl_sale.pro_id
JOIN tbl_pro_type ON tbl_pro_type.pro_type_id = tbl_product.pro_type_id
WHERE sal_date = curdate( )  ');

    //==============query select data for total product==================
    $data_product_total = $this->db->query('SELECT  sum(sal_quantity * sal_price ) AS total
FROM tbl_sale
INNER JOIN tbl_product ON tbl_product.pro_id = tbl_sale.pro_id
JOIN tbl_pro_type ON tbl_pro_type.pro_type_id = tbl_product.pro_type_id
WHERE sal_date = curdate( ) ');

    //==============query select for product data that has sold===============
    $data_product = $this->db->query('SELECT* FROM tbl_sale
INNER JOIN tbl_product ON tbl_product.pro_id = tbl_sale.pro_id
JOIN tbl_pro_type ON tbl_pro_type.pro_type_id = tbl_product.pro_type_id
WHERE sal_date = curdate( )  ');
    //===========loop in order to get value for total amount================
    foreach ($data_total_amount->result() as $rows) {
        $tal = $rows->total_amount;
        $credit_amount = $rows->credit_amount;
    }
    //=========loop in order to get value for total product============
    foreach ($data_product_amount->result() as $row) {
        $total_pro = $row->total_pro;
    }

    $total_amount = $total_pro + $tal;
    $totalall = $total_amount - $credit_amount;
    if ($data_product->num_rows() > 0) {  //========condition if data is store in the database ===========
        echo ' <div style="border:0px solid #ccc;font-size:20px;width:30%;margin:auto;text-align:center;padding:10px 0px 10px 0px;color:#008000;">Products</div>';
        echo '<table id="mytable" width="100%" cellspacing="0" cellpadding="0" >
             
              <tr style="text-align:center;color:#FFF;height:25px;">
                <th style="border:1px solid #ccc;">N&ordm</th>
                 <th style="border:1px solid #ccc;">Sell Date</th>
                 <th style="border:1px solid #ccc;">Seller</th>
                <th style="border:1px solid #ccc;"> Items</th>
                <th style="border:1px solid #ccc;">Quantity</th>
                <th style="border:1px solid #ccc;">Unit Price</th>
                <th style="border:1px solid #ccc;">Payment</th>
              </tr>';
        $j = 0;
        $i = 1;

        foreach ($data_product->result() as $value) {
            $j++;
            echo '<tr style="text-align:center;font-weight: lighter;" class="row';
            echo $j % 2;
            echo '">';
            echo '<td style="text-align:center; border:1px solid #ccc;" >' . $j . '</td>
            <td style="text-align:center; border:1px solid #ccc;" >' . $value->sal_date . '</td>
            <td style="text-align:center; border:1px solid #ccc;" >' . $this->session->userdata('use_username') . '</td>
            <td style="text-align:center; border:1px solid #ccc;" >' . $value->pro_name . '</td>
            <td  style="text-align:center; border:1px solid #ccc;" >' . $value->sal_quantity . '</td>
            <td style="text-align:center; border:1px solid #ccc;" >$' . $value->sal_price . '</td>
            <td style="text-align:center; border:1px solid #ccc;" >$' . $value->sal_price * $value->sal_quantity . '</th>
            </tr>';
            $i++;
        }
        echo '<tr style="background-color:#E8F6FE;">';
        echo ' <td colspan="6" style="text-align:right;font-size:16px;color:red;font-weight:Bold;">Total :<td>';
        foreach ($data_product_total->result() as $value) {
            echo '<b style="color:red;font-weight: Bold;"><center>$' . $value->total . '</center></b>';
        }
        echo '</tr></table>';
    }
    echo '<br/><br/><table align="right" id="mytable" width="100%" cellspacing="0" cellpadding="0" border="0"><tr style="background-color:#E8F6FE;">';
    echo ' <td colspan="3" style="text-align:right;font-size:16px;color:#008000;font-weight:Bold;width:90%;border:1px solid #ccc;">Total Amount :<br/><br/>Total Credit :<br/><br/>Today Income :<br/></td>';
    foreach ($data_product_total->result() as $value) {
        echo '<td style="color:red;font-weight: Bold;border:1px solid #ccc;" align="center">$' . $total_amount . '<br/><br/> $' . $credit_amount . '<br/><br/>$' . $totalall . '</td>';
    }
    echo '</table>';
} else {
    echo '<br/><br//><div style="margin:auto;width:100%;background-color:#E8F6FE;color:#008000;text-align:center;padding:10px 0px 10px 0px;">No Item sell today</div>';
}
echo '</fieldset>';
echo '</div>';
?>
</div>
